<template>
  <div class="detail_background">
    <div class="detail">
      <div class="detail_item">
        <span class="detail_item_label">需求类型:</span>
        <span class="detail_item_content">{{ subType }}</span>
      </div>
      <div class="detail_item">
        <span class="detail_item_label">姓名:</span>
        <span class="detail_item_content">{{ name }}</span>
      </div>
      <div class="detail_item">
        <span class="detail_item_label">联系方式:</span>
        <span class="detail_item_content">{{ mobile }}</span>
      </div>
      <div v-if="subType=='电站出售'">
        <div class="detail_item">
          <span class="detail_item_label">电站名称:</span>
          <span class="detail_item_content">{{ powerName }}</span>
        </div>
        <div class="detail_item">
          <span class="detail_item_label">所在区域:</span>
          <span class="detail_item_content">{{ region }}</span>
        </div>
        <div class="detail_item">
          <span class="detail_item_label">详细地址:</span>
          <span class="detail_item_content">{{ address }}</span>
        </div>
      </div>
      <div v-else-if="subType=='电站求购'">
        <div class="detail_item">
          <span class="detail_item_label">预算价位:</span>
          <span class="detail_item_content">{{ budgetPrice }}</span>
        </div>
        <div class="detail_item">
          <span class="detail_item_label">求购区域:</span>
          <span class="detail_item_content">{{ purchaseArea }}</span>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
import LoginManager from "@/utils/LoginManager";
import wxPromisify from "@/libs/wxPromisify";
import {getCustomerInfoByMobile} from "@/api";

export default {
  name: "registerDetail.vue",
  data() {
    return {
      subType: '',
      name: '',
      mobile: '',
      powerName: '',
      region: '',
      address: '',
      budgetPrice: '',
      purchaseArea: '',
    }
  },

  onLoad(options) {
    this.fetchLoginInfo();
    let params = {
      token: LoginManager.getToken(),
      mobile:options.mobile,
    }
    this.$Api.getCustomersByMobile(params)
        .then((res) => {
          console.log('res====', res);
          let data = res.data[0];
          this.subType=data.customersType=='1'?'电站求购':'电站出售';//客户类型 1是买方(代表电站求购)，2是卖方（代表电站出售）
          this.name = data.name;//客户姓名;
          this.mobile = data.mobile;//联系方式;
          this.powerName = data.powerName;//电站名称
          this.region = data.regionProvince + '-' + data.regionCity + '-' + data.regionArea;//省-市-区;
          this.address = data.address;//详细地址
          this.budgetPrice = data.budgetPrice;//预算价位
          this.purchaseArea = data.purchaseArea;//求购区域
          console.log('this.name==' + this.name);
          console.log('this.mobile==' + this.mobile);
          console.log('this.region==' + this.region);
        })
  },
  methods:{
    // async fetchLoginInfo() {
    //   if(this.$LoginManager.getLoginType()==="admin"){//业务员
    //     await this.$LoginManager.CheckLoginByCode();
    //     let isLogin = this.$LoginManager.checkLoginStatus();
    //     if (!isLogin) {
    //       await wxPromisify.navigateTo({
    //         url: '/pages/login/adminIndex'//业务员登录
    //       })
    //     }
    //   }else if(this.$LoginManager.getLoginType()===""||this.$LoginManager.getLoginType()===null || this.$LoginManager.getLoginType()===undefined){//以前没登陆过跳转到登录页
    //     await wxPromisify.navigateTo({
    //       url: '/pages/login/adminIndex'
    //     })
    //   }
    // },
    async fetchLoginInfo() {
      if(this.$LoginManager.getLoginType()==="admin"){//业务员
        let isLogin = this.$LoginManager.checkLoginStatus();
        if (!isLogin) {
          await wxPromisify.navigateTo({
            url: '/pages/login/adminIndex'//业务员登录
          })
        }else{
          let {returnCode, resultData} = await LoginManager.appletsCheckToken(LoginManager.getToken());//校验token是否过期
          if(returnCode!="0"){//token已过期 不存在
            let {returnCode, resultData} = await this.$LoginManager.CheckLoginByCode();//以前登陆过重新生成token
            if(returnCode!="0"){//returnCode等于0代表自动登录，不为0代表该openid在表中未查到，打开登录页面
              await wxPromisify.navigateTo({
                url: '/pages/login/adminIndex'//业务员登录
              })
            }
          }
        }
      }else if(!this.$LoginManager.getLoginType()){//以前没登陆过跳转到登录页
        await wxPromisify.navigateTo({
          url: '/pages/login/adminIndex'
        })
      }
    },
  }
}
</script>

<style scoped lang="scss">
.detail_background {
  min-height: 100VH;
  background: #F5F5F5;
}

.detail {
  width: 750px;
  height: 80%;
  background: #FFFFFF;
  margin-top: 24px;
  margin-bottom: 24px;
}
.detail_item {
  margin-left: 60px;
  margin-right: 60px;
  height: 114px;
//position: relative;
  border-bottom: 1px solid #E6E6E6;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.detail_item:last-child {
  border-bottom: 0;
}

.detail_item_label {
//display: inline-block;
  font-size: 32px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #333333;
  line-height: 32px;
}

.detail_item_content {
//margin-left: 18px;
  color: #333333;
  text-align: right;
}
</style>